#ifndef LOGGER_H
#define LOGGER_H

#include <stdint.h>
#include <common/Runnable.h>
#define ORBSUBSCRIBER_WORKAROUND_NAMESPACE logger
#include <common/orbhelper.h>
#include <uORB/uORB.h>
#include <uORB/topics/sensor_combined.h>
#include <uORB/topics/vehicle_attitude.h>
#include <uORB/topics/vehicle_gps_position.h>
#include <uORB/topics/vehicle_global_position.h>
#include <uORB/topics/sim_sensors.h>
#include <uORB/topics/zorfcs_state.h>
#include <uORB/topics/safety.h>
#include <uORB/topics/sdzorlog_status.h>

class Logger : public Runnable {
public:
	Logger();
	virtual ~Logger();
	
private:
	virtual void run();
	bool isLoggingRequest();
	void start();
	void stop();
	bool getIndex(int &index);
	void writeHead();
	void write();
	void writePacket(uint8_t id, int size);
	int putDataAA();
	void updateOrbData();
	void publishStatus(bool failure);

	static const uint8_t version_;
	
	bool logging_;

	static const char *mountpoint_;
	int fd_;

	static const int bufferSize_;
	uint8_t *buffer_;
	
	int stopCnt_;

	orbhelper::OrbSubscriber<sensor_combined_s, ORB_ID(sensor_combined)> sensor_combined_;
	orbhelper::OrbSubscriber<vehicle_attitude_s, ORB_ID(vehicle_attitude)> vehicle_attitude_;
	orbhelper::OrbSubscriber<vehicle_gps_position_s, ORB_ID(vehicle_gps_position)> vehicle_gps_position_;
	orbhelper::OrbSubscriber<vehicle_global_position_s, ORB_ID(vehicle_global_position)> vehicle_global_position_;
	orbhelper::OrbSubscriber<sim_sensors_s, ORB_ID(sim_sensors)> sim_sensors_;
	orbhelper::OrbSubscriber<zorfcs_state_s, ORB_ID(zorfcs_state)> zorfcs_state_;
	orbhelper::OrbSubscriber<safety_s, ORB_ID(safety)> safety_;
	orbhelper::OrbPublisher<sdzorlog_status_s, ORB_ID(sdzorlog_status)> sdzorlog_status_;
};

#endif
